<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE>
<html>
<head>
    <base href="<%=basePath%>">
    <title></title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <link rel="stylesheet" type="text/css" href="css/edittable.css"  ></link>
    <link rel="stylesheet" type="text/css" href="css/validate.css"  ></link>
    <script type="text/javascript"  src="js/jquery-1.8.0.js"></script>
    <style>
        .info{
            color: green;
            font-weight: bold;
        }
        .error{
            color: red;
            font-weight: bold;
        }

    </style>
    <script>
        $(function(){
            $("input[type=text]").focus(function(){
                $(this).addClass("input_focus");
            }).blur(function(){
                $(this).removeClass("input_focus");
            });

            $(".form_btn").hover(function(){
                    $(this).css("color","red").css("background","#6FB2DB");},
                function(){
                    $(this).css("color","#295568").css("background","#BAD9E3");
                });
        });
        $(function() {
            $("#goodsName").keyup(function () {
                var s = $("#goodsName").val();
                var e = /^[^\s]{2,15}$/;
                if (e.test(s) == false) {
                    $("#regname").html("校验失败，格式错误").removeClass().addClass("error");
                } else {
                    $.ajax({
                        url: "GoodsServlet",
                        type: "post",
                        data: {
                            flag: "checkadd", goodsName: s
                        },
                        success: function (data) {
                            if (data == "1")
                                $("#regname").html("名称已存在").removeClass().addClass("error");
                            if (data == "0")
                                $("#regname").html("名称可用").removeClass().addClass("info");
                        }
                    });
                }
            });
        });

        $(function () {
            $("#sub").click(function () {
                var a=$("label#regname").text();
                var a1="名称可用";
                if(a==a1||"".equals(a))
                    return confirm("确认提交吗");
                else return false;
            }) ;
        });
        $(function () {
            $("#imgfile").change(function () {
                var a="$('#imgfile').val()";
                // $.ajax({
                //     url: "GoodsServlet",
                //     type: "post",
                //     data: {
                //         flag: "show", pic: a
                //     },
                //     success: function (data) {
                $("#div1").innerText("<img src='"+data+"'/>");
                //         }
                //     });
            });
        });

    </script>
</head>
<body>
<div class ="div_title">
    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>用户修改</span></div>
</div>
<form action="GoodsServlet" method="post" enctype="multipart/form-data">
    <input type="hidden" name="flag" value="updateinfo" />
    <table class="edit_table" >
        <tr>
            <td class="td_info">商品名称:</td>	<td class="td_input">
            <input type="text" name="goodsName" id="goodsName" class="txtbox" value="${goodsinfo.goodsName}" />
            <label id="regname"></label> </td>
            <td><label>2-20位非空白字符</label></td>
        </tr>
        <tr>
            <td class="td_info">所属分类:</td>	<td>
            大分类：<input name="bigCateId" value="${goodsinfo.bigC()}"><br>

            小分类：<input name="smallCateId" value="${goodsinfo.smallC()}">

        </td>
            <td><label>请指定所属分类</label></td>
        </tr>
        <tr>
            <td class="td_info">计量单位:</td>
            <td>
                <input type="text" id="unit"  name="unit" class="txtbox" value="${goodsinfo.unit}"/>
            </td>
        </tr>
        <tr>
            <td class="td_info">商品价格:</td>	<td>
            <input type="text" name="price" value="${goodsinfo.price}">
        </td>
        </tr>
        <tr>
            <td class="td_info">生产厂商:</td>	<td>
            <input type="text" name="producter" value="${goodsinfo.producter}">
        </td>
        </tr>
        <tr>
            <td class="td_info">商品图片:</td>
            <td>
                <input type="file" name="pic" id="imgfile"  />
                <img src="GoodsServlet?flag=show&id=${goodsinfo.id}" style="width: 200px;height: 150px">
            </td>
        </tr>
        <tr>
            <td class="td_info">备注信息:</td>	<td>
            <textarea rows="7" cols="24" name="des" class="txtarea"  >${goodsinfo.des}</textarea>

        </tr>

        <tr>
            <td class="td_info"> </td>	<td>
            <input class="form_btn" type="submit" id="sub" value="提交" />
            <input type="reset"  class="form_btn" value="重置" />
            <label>${msg}</label>
        </td>	<td class="info"> &nbsp;</td>
        </tr>
    </table>
</form>
</body>
</html>
